package HP.Demo;

import java.util.Scanner;

public class ShangPinGouMai {
    public static void main(String[] args) {
        String s1 = "T恤";
        double p1 = 245;
        int n1 = 2;
        String s2 = "网球鞋";
        double p2 = 570;
        int n2 = 1;
        String s3 = "网球拍";
        double p3 = 320;
        int n3 = 1;

        double totalmoney = 0;//总价
        //购物车
        int g1 = 0;
        int g2 = 0;
        int g3 = 0;
        //循环显示菜单
        while (true) {
            System.out.println("-------------------");
            System.out.println("商品列表:");
            System.out.println("1.T恤");
            System.out.println("2.网球鞋");
            System.out.println("3.网球拍");
            //System.out.println("0.查看购物车");
            System.out.println("-------------------");

            System.out.println("请输入需要购买的商品编号:");
            Scanner scanner = new Scanner(System.in);
            int input = scanner.nextInt();

            System.out.println("请输入需要购买的数量:");
            int input_num = scanner.nextInt();

            String a = ": ¥";
            switch (input) {
                case 1:
                    System.out.println(s1 + a + p1);
                    g1++;
                   // System.out.println(s1 + "已添加到购物车:");
                    System.out.println("商品名称:"+s1+" 数量:"+input_num+" 小计:"+(p1*input_num));
                    totalmoney+=(p1*input_num);
                    System.out.println("总计:"+totalmoney);
                    System.out.println("___________________________");

                    break;
                case 2:
                    System.out.println(s2 + a + p2);
                    g2++;
                    System.out.println("商品名称:"+s2+" 数量:"+input_num+" 小计:"+(p2*input_num));
                    totalmoney+=(p2*input_num);
                    System.out.println("总计:"+totalmoney);
                    System.out.println("___________________________");
                   // System.out.println(s1 + "已添加到购物车:");
                    break;
                case 3:
                    System.out.println(s3 + a + p3);
                    g3++;
                    System.out.println("商品名称:"+s3+" 数量:"+input_num+" 小计:"+(p3*input_num));
                    totalmoney+=(p3*input_num);
                    System.out.println("总计:"+totalmoney);
                    System.out.println("___________________________");
                    //System.out.println(s1 + "已添加到购物车:");
                    break;
                case 0:
                    System.out.println("您购物车中的商品:");
                    System.out.println("**************");
                    System.out.println(s1 + "    " + g1);
                    System.out.println(s2 + " " + g2);
                    System.out.println(s3 + " " + g3);
                    System.out.println("**************");
                    break;
                default:
                    System.out.println("商品不存在!");
                    break;
            }
           // System.out.println("是否继续购物(y/n)?输入'j'结算.");
            System.out.println("是否继续购物(y/n)?");
            Scanner jixu = new Scanner(System.in);
            String jixugouwu = jixu.nextLine();
            if (jixugouwu.equals("n")) {
                break;
            }/*else if(jixugouwu.equals("y")){

            }else if(jixugouwu.equals("j")) {
                System.out.println("xxx");
            }*/
        }
    }
/*    public static void jiesuan(int g1,int g2,int g3){

    }*/
}
